﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Text;
using System.Windows.Forms;
using Gencode.PrsCommon.App;

namespace Personalplaner.Options
{
    [ToolboxItem(false)]
	public partial class AblaufOptions : Gencode.Gengui.GUControl/* UserControl*/, IOptionsInterface
	{
		bool changed = false;

		public AblaufOptions()
		{
			InitializeComponent();
			SetOptions();
		}

		private void SetOptions()
		{
			bool check = false;

			if ((int)Option.NumberValue("ShemaOptions", 1) == 1) { check = true; } else { check = false; }
			checkShemaChange.Checked = check;
			txtSchemaName.Text = Option.StringValue("ShemaOptions", 1);

			txtSchemaName.Enabled = check;
			rdoOverwrite.Enabled = check;
			rdoNew.Enabled = check;
			rdoLeaveOld.Enabled = check;

			int saveType = (int)Option.NumberValue("SchemaSaveType", 1);

			if (saveType == 1)
				rdoNew.Checked = true;
			if (saveType == 2)
				rdoLeaveOld.Checked = true;
			if (saveType == 3)
				rdoOverwrite.Checked = true;

			changed = false;
		}

		#region IOptionsInterface Members

		public void save()
		{
			if (changed)
			{
				if (txtSchemaName.Text != "")
				{
					double check = 0;

					if (checkShemaChange.Checked) { check = 1; } else { check = 0; }
					SaveOptions.SaveData("ShemaOptions", 1, check, txtSchemaName.Text);

					int saveType = 0;
					if (rdoNew.Checked == true)
						saveType = 1;
					if (rdoLeaveOld.Checked == true)
						saveType = 2;
					if (rdoOverwrite.Checked == true)
						saveType = 3;
					SaveOptions.SaveData("SchemaSaveType", 1, saveType, "");

					changed = false;
				}
			}
		}

		public bool checkIfChanged()
		{
			return changed;
		}

		#endregion

		private void checkShemaChange_CheckedChanged(object sender, EventArgs e)
		{
			changed = true;
			txtSchemaName.Enabled = checkShemaChange.Checked;
			rdoLeaveOld.Enabled = checkShemaChange.Checked;
			rdoNew.Enabled = checkShemaChange.Checked;
			rdoOverwrite.Enabled = checkShemaChange.Checked;
		}

		private void txtSchemaName_TextChanged(object sender, EventArgs e)
		{
			changed = true;
		}

		private void rdoNew_CheckedChanged(object sender, EventArgs e)
		{
			changed = true;
		}

		private void rdoLeaveOld_CheckedChanged(object sender, EventArgs e)
		{
			changed = true;
		}

		private void rdoOverwrite_CheckedChanged(object sender, EventArgs e)
		{
			changed = true;
		}

		private void chkLaufendeSchema_CheckedChanged(object sender, EventArgs e)
		{
			changed = true;
		}
	}
}
